package cn.ibizlab.odoo.core.odoo_payment.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ipayment_acquirer;
import cn.ibizlab.odoo.core.odoo_payment.domain.Payment_acquirer;
import cn.ibizlab.odoo.core.odoo_payment.filter.Payment_acquirerSearchContext;
import cn.ibizlab.odoo.core.odoo_payment.service.IPayment_acquirerService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[付款收单方] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Payment_acquirerServiceImpl implements IPayment_acquirerService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ipayment_acquirerClientService payment_acquirerClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ipayment_acquirer clientModel = payment_acquirerClientService.createModel();
        clientModel.setId(id);
        payment_acquirerClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Payment_acquirer payment_acquirer) {
        boolean bOk = false ;
        Ipayment_acquirer clientModel = this.convert2Model(payment_acquirer,null);
        payment_acquirerClientService.update(clientModel) ;
        this.convert2Domain(clientModel,payment_acquirer) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //payment_acquirerClientService.removeBatch(payment_acquirers) ;

    }

    @Override
    public void createBatch(List<Payment_acquirer> payment_acquirers, int batchSize) {

                        //payment_acquirerClientService.createBatch(payment_acquirers,batchSize) ;

    }

    @Override
    public Payment_acquirer get(Integer id) {
        Ipayment_acquirer clientModel = payment_acquirerClientService.createModel();
        clientModel.setId(id);
        payment_acquirerClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Payment_acquirer get(Payment_acquirer payment_acquirer) {
        Payment_acquirer retpayment_acquirer = this.get(payment_acquirer.getId()) ;
    	BeanCopier copier=BeanCopier.create(retpayment_acquirer.getClass(), payment_acquirer.getClass(), false);
        copier.copy(retpayment_acquirer, payment_acquirer, null);
        return payment_acquirer ;
    }

    @Override
    public boolean create(Payment_acquirer payment_acquirer) {
        boolean bOk = false ;
        Ipayment_acquirer clientModel = this.convert2Model(payment_acquirer,null);
        payment_acquirerClientService.create(clientModel) ;
        this.convert2Domain(clientModel,payment_acquirer);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Payment_acquirer> payment_acquirers, int batchSize) {

        //payment_acquirerClientService.updateBatch(payment_acquirers,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Payment_acquirer> searchDefault(Payment_acquirerSearchContext context) {
        List<Payment_acquirer> list = new ArrayList<Payment_acquirer>();
        Page<cn.ibizlab.odoo.core.client.model.Ipayment_acquirer> clientModelList = payment_acquirerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ipayment_acquirer clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Payment_acquirer>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据日记账查询
     */
    @Override
    public Page<Payment_acquirer> selectByOdoo_journal(Integer id){
        Payment_acquirerSearchContext context = new Payment_acquirerSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Payment_acquirer> list = new ArrayList<Payment_acquirer>();
        Page<cn.ibizlab.odoo.core.client.model.Ipayment_acquirer> clientModelList = payment_acquirerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ipayment_acquirer clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Payment_acquirer>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Payment_acquirer> selectByOdoo_company(Integer id){
        Payment_acquirerSearchContext context = new Payment_acquirerSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Payment_acquirer> list = new ArrayList<Payment_acquirer>();
        Page<cn.ibizlab.odoo.core.client.model.Ipayment_acquirer> clientModelList = payment_acquirerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ipayment_acquirer clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Payment_acquirer>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Payment_acquirer> selectByOdoo_create(Integer id){
        Payment_acquirerSearchContext context = new Payment_acquirerSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Payment_acquirer> list = new ArrayList<Payment_acquirer>();
        Page<cn.ibizlab.odoo.core.client.model.Ipayment_acquirer> clientModelList = payment_acquirerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ipayment_acquirer clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Payment_acquirer>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Payment_acquirer> selectByOdoo_write(Integer id){
        Payment_acquirerSearchContext context = new Payment_acquirerSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Payment_acquirer> list = new ArrayList<Payment_acquirer>();
        Page<cn.ibizlab.odoo.core.client.model.Ipayment_acquirer> clientModelList = payment_acquirerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ipayment_acquirer clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Payment_acquirer>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ipayment_acquirer convert2Model(Payment_acquirer domain , Ipayment_acquirer model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = payment_acquirerClientService.createModel() ;
        }

         if(domain.getFees_implementedDirtyFlag())
            model.setFees_implemented(domain.getFees_implemented());
         if(domain.getDescriptionDirtyFlag())
            model.setDescription(domain.getDescription());
         if(domain.getImageDirtyFlag())
            model.setImage(domain.getImage());
         if(domain.getDone_msgDirtyFlag())
            model.setDone_msg(domain.getDone_msg());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getPayment_icon_idsDirtyFlag())
            model.setPayment_icon_ids(domain.getPayment_icon_ids());
         if(domain.getWebsite_publishedDirtyFlag())
            model.setWebsite_published(domain.getWebsite_published());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getFees_int_varDirtyFlag())
            model.setFees_int_var(domain.getFees_int_var());
         if(domain.getFees_activeDirtyFlag())
            model.setFees_active(domain.getFees_active());
         if(domain.getRegistration_view_template_idDirtyFlag())
            model.setRegistration_view_template_id(domain.getRegistration_view_template_id());
         if(domain.getWebsite_idDirtyFlag())
            model.setWebsite_id(domain.getWebsite_id());
         if(domain.getPost_msgDirtyFlag())
            model.setPost_msg(domain.getPost_msg());
         if(domain.getEnvironmentDirtyFlag())
            model.setEnvironment(domain.getEnvironment());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getImage_smallDirtyFlag())
            model.setImage_small(domain.getImage_small());
         if(domain.getToken_implementedDirtyFlag())
            model.setToken_implemented(domain.getToken_implemented());
         if(domain.getFees_dom_fixedDirtyFlag())
            model.setFees_dom_fixed(domain.getFees_dom_fixed());
         if(domain.getFees_int_fixedDirtyFlag())
            model.setFees_int_fixed(domain.getFees_int_fixed());
         if(domain.getModule_idDirtyFlag())
            model.setModule_id(domain.getModule_id());
         if(domain.getAuthorize_implementedDirtyFlag())
            model.setAuthorize_implemented(domain.getAuthorize_implemented());
         if(domain.getPayment_flowDirtyFlag())
            model.setPayment_flow(domain.getPayment_flow());
         if(domain.getSpecific_countriesDirtyFlag())
            model.setSpecific_countries(domain.getSpecific_countries());
         if(domain.getFees_dom_varDirtyFlag())
            model.setFees_dom_var(domain.getFees_dom_var());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getPre_msgDirtyFlag())
            model.setPre_msg(domain.getPre_msg());
         if(domain.getCountry_idsDirtyFlag())
            model.setCountry_ids(domain.getCountry_ids());
         if(domain.getQr_codeDirtyFlag())
            model.setQr_code(domain.getQr_code());
         if(domain.getPending_msgDirtyFlag())
            model.setPending_msg(domain.getPending_msg());
         if(domain.getImage_mediumDirtyFlag())
            model.setImage_medium(domain.getImage_medium());
         if(domain.getView_template_idDirtyFlag())
            model.setView_template_id(domain.getView_template_id());
         if(domain.getInbound_payment_method_idsDirtyFlag())
            model.setInbound_payment_method_ids(domain.getInbound_payment_method_ids());
         if(domain.getSo_reference_typeDirtyFlag())
            model.setSo_reference_type(domain.getSo_reference_type());
         if(domain.getModule_stateDirtyFlag())
            model.setModule_state(domain.getModule_state());
         if(domain.getCancel_msgDirtyFlag())
            model.setCancel_msg(domain.getCancel_msg());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getProviderDirtyFlag())
            model.setProvider(domain.getProvider());
         if(domain.getSave_tokenDirtyFlag())
            model.setSave_token(domain.getSave_token());
         if(domain.getCapture_manuallyDirtyFlag())
            model.setCapture_manually(domain.getCapture_manually());
         if(domain.getError_msgDirtyFlag())
            model.setError_msg(domain.getError_msg());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Payment_acquirer convert2Domain( Ipayment_acquirer model ,Payment_acquirer domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Payment_acquirer();
        }

        if(model.getFees_implementedDirtyFlag())
            domain.setFees_implemented(model.getFees_implemented());
        if(model.getDescriptionDirtyFlag())
            domain.setDescription(model.getDescription());
        if(model.getImageDirtyFlag())
            domain.setImage(model.getImage());
        if(model.getDone_msgDirtyFlag())
            domain.setDone_msg(model.getDone_msg());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getPayment_icon_idsDirtyFlag())
            domain.setPayment_icon_ids(model.getPayment_icon_ids());
        if(model.getWebsite_publishedDirtyFlag())
            domain.setWebsite_published(model.getWebsite_published());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getFees_int_varDirtyFlag())
            domain.setFees_int_var(model.getFees_int_var());
        if(model.getFees_activeDirtyFlag())
            domain.setFees_active(model.getFees_active());
        if(model.getRegistration_view_template_idDirtyFlag())
            domain.setRegistration_view_template_id(model.getRegistration_view_template_id());
        if(model.getWebsite_idDirtyFlag())
            domain.setWebsite_id(model.getWebsite_id());
        if(model.getPost_msgDirtyFlag())
            domain.setPost_msg(model.getPost_msg());
        if(model.getEnvironmentDirtyFlag())
            domain.setEnvironment(model.getEnvironment());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getImage_smallDirtyFlag())
            domain.setImage_small(model.getImage_small());
        if(model.getToken_implementedDirtyFlag())
            domain.setToken_implemented(model.getToken_implemented());
        if(model.getFees_dom_fixedDirtyFlag())
            domain.setFees_dom_fixed(model.getFees_dom_fixed());
        if(model.getFees_int_fixedDirtyFlag())
            domain.setFees_int_fixed(model.getFees_int_fixed());
        if(model.getModule_idDirtyFlag())
            domain.setModule_id(model.getModule_id());
        if(model.getAuthorize_implementedDirtyFlag())
            domain.setAuthorize_implemented(model.getAuthorize_implemented());
        if(model.getPayment_flowDirtyFlag())
            domain.setPayment_flow(model.getPayment_flow());
        if(model.getSpecific_countriesDirtyFlag())
            domain.setSpecific_countries(model.getSpecific_countries());
        if(model.getFees_dom_varDirtyFlag())
            domain.setFees_dom_var(model.getFees_dom_var());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getPre_msgDirtyFlag())
            domain.setPre_msg(model.getPre_msg());
        if(model.getCountry_idsDirtyFlag())
            domain.setCountry_ids(model.getCountry_ids());
        if(model.getQr_codeDirtyFlag())
            domain.setQr_code(model.getQr_code());
        if(model.getPending_msgDirtyFlag())
            domain.setPending_msg(model.getPending_msg());
        if(model.getImage_mediumDirtyFlag())
            domain.setImage_medium(model.getImage_medium());
        if(model.getView_template_idDirtyFlag())
            domain.setView_template_id(model.getView_template_id());
        if(model.getInbound_payment_method_idsDirtyFlag())
            domain.setInbound_payment_method_ids(model.getInbound_payment_method_ids());
        if(model.getSo_reference_typeDirtyFlag())
            domain.setSo_reference_type(model.getSo_reference_type());
        if(model.getModule_stateDirtyFlag())
            domain.setModule_state(model.getModule_state());
        if(model.getCancel_msgDirtyFlag())
            domain.setCancel_msg(model.getCancel_msg());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getProviderDirtyFlag())
            domain.setProvider(model.getProvider());
        if(model.getSave_tokenDirtyFlag())
            domain.setSave_token(model.getSave_token());
        if(model.getCapture_manuallyDirtyFlag())
            domain.setCapture_manually(model.getCapture_manually());
        if(model.getError_msgDirtyFlag())
            domain.setError_msg(model.getError_msg());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
